package landlords;

/**
 * 斗地主主程序
 */
public class PlayDemo {
    public static void main(String[] args) {

        // 生成一副扑克牌
        Poker poker = new Poker();
        System.out.println("扑克牌共" + poker.getCardCount() + "只");

        // 设置三个玩家，并设定两人为农民，一个为地主
        int playCount = 3;
        Player player1 = new Player("玩家1", "农民");
        Player player2 = new Player("玩家2", "农民");
        Player player3 = new Player("玩家3", "地主");

        // 三个玩家按顺序抓牌
        int i;
        for (i = 0; i < poker.getCardCount() - playCount; i++) {
            if (i % playCount == 0) {
                player1.draw(poker.getCards().get(i));
            } else if (i % playCount == 1) {
                player2.draw(poker.getCards().get(i));
            } else if (i % playCount == 2) {
                player3.draw(poker.getCards().get(i));
            }
        }

        // 地主拿剩余底牌
        while (i < poker.getCardCount()) {
            player3.draw(poker.getCards().get(i));
            i++;
        }

        // 展示三个玩家洗牌后手上的牌面及最大和最小的牌
        player1.sort();
        System.out.println(player1.toString());
        System.out.println("最大牌是："+player1.max().toString()+",最小牌是："+player1.min().toString());
        player2.sort();
        System.out.println(player2.toString());
        System.out.println("最大牌是："+player2.max().toString()+",最小牌是："+player2.min().toString());
        player3.sort();
        System.out.println(player3.toString());
        System.out.println("最大牌是："+player3.max().toString()+",最小牌是："+player3.min().toString());

        // 大王是否在地主手里
        if (player3.binarySearch(new Card("JOKER","大王"))>=0){
            System.out.println("大王在"+player3.getType()+player3.getName()+"手里");
        }

        // 统计有几手炸弹
        System.out.println(player1.getName()+"手上有"+player1.frequency()+"手炸弹");
        System.out.println(player2.getName()+"手上有"+player2.frequency()+"手炸弹");
        System.out.println(player3.getName()+"手上有"+player2.frequency()+"手炸弹");

    }
}
